#include<iostream>
using namespace std;
#define INFINITY 65535;
#define maxvex 5
 
typedef struct 
{
	char vexs[maxvex];   //顶点表
	int arc[maxvex][maxvex];   //邻接矩阵
	int numvertex;              //图中当前的顶点数和边数
	int numedge;      
}MGraph;
 
void CreateMGaph(MGraph &g)
{
	int i, j, k, w;
	cout << "请输入顶点数和边数：" << endl;
	cin >> g.numvertex;
	cin >> g.numedge;
	cout << "请输入结点的信息" << endl;
	
    //读入顶点信息，建立顶点结点
	for (i = 0;i < g.numvertex;i++)
            cin >> &(g.vexs[i]);
        
    //邻接矩阵初始化
	for (i=0;i<g.numvertex;i++)
	{
		for (j = 0;j < g.numvertex;j++)
			g.arc[i][j] = INFINITY;
	}
	//建立邻接矩阵
	for (k=0;k<g.numedge;k++)
	{
		cout << "输入边（vi,vj）上的下标i，下标j和权w:\n";
		cin >> i >> j >> w;
		g.arc[i][j] = w;
		g.arc[j][i] = g.arc[i][j];    //因为是无向图，所以矩阵对称
	}
}
void print(MGraph *mg)
{
    cout<<"邻接矩阵："<<endl;
    for (int i=0;i<mg->numvertex;i++)
	{
		for (int j = 0;j < mg->numvertex;j++)
			cout << mg->arc[i][j]<<"   ";
		cout << endl;
	}
}
int main()
{
	MGraph mg;
	CreateMGaph(mg);
	print(&mg);
}